class AccountController < ApplicationController
  
  hobo_controller
  
  def change_password
    @user = User.new
    if request.post?
      @user = Hobo.user_model.authenticate(current_user.login, params[:current_password])
      if @user
        if @user.update_attributes(params[:user])
          flash[:notice] = "Password successfully changed."
          redirect_back_or_default(:controller => :front, :action => :index)
        else
          render :action => :change_password and return
        end
      else
        flash[:notice] = "Wrong current password."
        render :action => :change_password and return
      end
    end
  end
  
  def reset_password
    if request.post?
      user = User.find_by_email(params[:email])      
      if user
        # TODO: fill
        user.reset_password
        flash[:notice] = "Password successfully reset. Please check your email."
        redirect_back_or_default(:controller => :front, :action => :index)
      else
        flash[:notice] = "The user " + params[:email].to_s + " doesn't exist."
      end
    end
  end
  
end
